Update to new-style rustc CLI args
authorCorey Richardson <corey@octayn.net>
Sun, 21 Dec 2014 06:41:02 +0000 (01:41 -0500)
committerCorey Richardson <corey@octayn.net>
Sun, 21 Dec 2014 07:00:02 +0000 (02:00 -0500)
src/cargo/ops/cargo_rustc/mod.rs

index c08e060c6d8e42e22936728d9ade9d0b6e3c1ead..82340b57584e96a3f657a0c88c3034e12cf2531c 100644 (file)
@@ -46,6 +46,10 @@ pub struct TargetConfig {
 /// The second element of the tuple returned is the target triple that rustc
 /// is a host for.
 pub fn rustc_version() -> CargoResult<(String, String)> {
+    rustc_new_version().or_else(|_| rustc_old_version())
+}
+
+pub fn rustc_old_version() -> CargoResult<(String, String)> {
     let output = try!(try!(util::process("rustc"))
         .arg("-v")
         .arg("verbose")
@@ -65,6 +69,25 @@ pub fn rustc_version() -> CargoResult<(String, String)> {
     Ok((output, triple))
 }
 
+pub fn rustc_new_version() -> CargoResult<(String, String)> {
+    let output = try!(try!(util::process("rustc"))
+        .arg("-vV")
+        .exec_with_output());
+    let output = try!(String::from_utf8(output.output).map_err(|_| {
+        internal("rustc -v didn't return utf8 output")
+    }));
+    let triple = {
+        let triple = output.as_slice().lines().filter(|l| {
+            l.starts_with("host: ")
+        }).map(|l| l.slice_from(6)).next();
+        let triple = try!(triple.require(|| {
+            internal("rustc -v didn't have a line for `host:`")
+        }));
+        triple.to_string()
+    };
+    Ok((output, triple))
+}
+
 // This is a temporary assert that ensures the consistency of the arguments
 // given the current limitations of Cargo. The long term fix is to have each
 // Target know the absolute path to the build location.